package com.tqw.es.repository;

import com.tqw.es.pojo.Item;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

/**
 * @author Jim
 */
public interface ItemRepository extends ElasticsearchRepository<Item,Integer> {
    /**
     * 根据商品标题搜索商品
     * @param key 关键词
     * @param pageable 分页参数
     * @return 搜索结果
     */
    @Highlight(parameters = @HighlightParameters(preTags = "<em>",postTags = "</em>"),fields = {@HighlightField(name = "title")})
    List<SearchHit<Item>> findByTitle(String key, Pageable pageable);
}
